package com.crm.dao.client;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.crm.pojo.ClientTransfer;

public interface ClientTransferDao extends CrudRepository<ClientTransfer, Long> {

	/**
	 * 查询所有的转移日志
	 * @param pageable
	 * @return
	 */
	@Query("from ClientTransfer c where c.clientTransferIsDel !='是' order by c.operateDate ")
	public List<ClientTransfer> queryAllClientTransfer(Pageable pageable);
	
	/**
	 * 查询所有的转移日志的数量
	 * @return
	 */
	@Query("select count(*) from ClientTransfer c where c.clientTransferIsDel !='是' order by c.operateDate")
	public Long queryCountAllClientTransfer();
	
	/**
	 * 根据转入用户查找转移日志
	 * @param inClientId
	 * @param pageable
	 * @return
	 */
	@Query("from ClientTransfer c where c.inClientId = ?1 and c.clientTransferIsDel !='是' order by c.operateDate")
	public List<ClientTransfer> queryClientTransferByInClientId(BigDecimal inClientId, Pageable pageable);
	
	/**
	 * 根据转入用户查找转移日志的数量
	 * @param inClientId
	 * @return
	 */
	@Query("select count(*) from ClientTransfer c where c.inClientId = ?1 and c.clientTransferIsDel !='是' order by c.operateDate")
	public Long queryCountClientTransferByInClientId(BigDecimal inClientId);

	/**
	 * 根据转出用户查找转移日志
	 * @param outClentId
	 * @param pageable
	 * @return
	 */
	@Query("from ClientTransfer c where c.outClentId = ?1 and c.clientTransferIsDel !='是' order by c.operateDate")
	public List<ClientTransfer> queryClientTransferByOutClientId(BigDecimal outClentId, Pageable pageable);
	
	/**根据转出用户查找转移日志
	 * 
	 * @param outClentId
	 * @return
	 */
	@Query("select count(*) from ClientTransfer c where c.outClentId = ?1 and c.clientTransferIsDel !='是' order by c.operateDate")
	public Long queryCountClientTransferByOutClientId(BigDecimal outClentId);
}
